//
//  SynthesisImageVC.m
//  first
//
//  Created by 毕小强 on 16/11/8.
//  Copyright © 2016年 毕小强. All rights reserved.
//

#import "SynthesisImageVC.h"

@interface SynthesisImageVC ()
@property(nonatomic,strong) UIImageView *backImageView;
@end

@implementation SynthesisImageVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.backImageView=[[UIImageView alloc]init];
    _backImageView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
    _backImageView.image = [self CoregraphicsSynthesisView:[self create] Size:self.view.bounds.size];
    [self.view addSubview:_backImageView];
}
-(UIView*)create{
    UIView*back = [[UIView alloc]initWithFrame:CGRectMake(0, 0,self.view.bounds.size.width, self.view.bounds.size.height)];
    
    UITextField *Fld=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, self.view.bounds.size.width-200, 50)];
    Fld.borderStyle = UITextBorderStyleRoundedRect;
    Fld.text = @"这是测试";
    [back addSubview:Fld];
    
    return back;
}
-(UIImage*)CoregraphicsSynthesisView:(UIView *)cView Size:(CGSize)size{
    //UIGraphicsBeginImageContext(cView.bounds.size); 图片会失真
    UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);//更清晰
    CGContextRef context = UIGraphicsGetCurrentContext();
    [cView.layer renderInContext:context];
    UIImage*img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
